using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Ivory;
using DefCore;
using FarseerPhysics.SamplesFramework;
using DefCore.Tools;
using Krypton;
using Defender.GameTypes;

namespace Defender
{
    public class Launcher : Microsoft.Xna.Framework.Game
    {
        protected ScreenManager Manager;

        public Launcher()
        {
            Content.RootDirectory = "Content";
            Manager = new ScreenManager(this, "data/config.cfg");
            Objects.GameObject = this;
            
            this.Window.Title = string.Format("Defender {0}", Globals.Version);
        }

        protected override void Initialize()
        {
            Manager.SetMainMenu(new MainMenu(this));
            Manager.AddGameScreen(TestingPit.Key, new TestingPit());
            ConvertUnits.SetDisplayUnitToSimUnitRatio(184);
            base.Initialize();
        }
        protected override void LoadContent()
        {
            //Singleton Resource loading
            ResourceBin.Instance.Load();
            FontBin.Instance.Load();
            TileBin.Instance.Load();
            StructureBin.Instance.Load();
            LightFactory.LightTexture = LightTextureBuilder.CreatePointLight(Objects.GameObject.GraphicsDevice, 256);
            Manager.LoadScreenManager();
        }

        protected override void Update(GameTime gameTime)
        {
            Manager.Update(gameTime);

            if (Keyboard.GetState().IsKeyDown(Keys.F9))
                this.Exit();

            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            Manager.Draw(gameTime);

            base.Draw(gameTime);
        }
    }
}
